How to test if some attribute is set of not

Hello,

I would like to to something like that

Object o = ...
if isEmtpy(o."Some Attribute") then
{
   ...
}
else
{
   ...
}

 


However I could not find any stuch function as

 

bool isEmpty(AttrRef )

.

Any help is welcome.
Vincent.


SystemAdmin - Wed Feb 23 06:44:33 EST 2011

Re: How to test if some attribute is set of not
SystemAdmin - Wed Feb 23 06:50:23 EST 2011

Hello,

Just to add that after some search I have found this way:
 

Object o = current
 
if (null o."Object Text" "") print "=>empty\n"; else print "=>no empty\n";

 


1. Is that the standard way
2. That seems to imply a cast to string, will it work for any kind of attribute type ?

 

Re: How to test if some attribute is set of not
Mathias Mamsch - Wed Feb 23 07:49:51 EST 2011

SystemAdmin - Wed Feb 23 06:50:23 EST 2011

Hello,

Just to add that after some search I have found this way:
 

Object o = current
 
if (null o."Object Text" "") print "=>empty\n"; else print "=>no empty\n";

 


1. Is that the standard way
2. That seems to imply a cast to string, will it work for any kind of attribute type ?

 

Sometimes you may want to check if the attribute does not have its "default" value (which could be different from <empty>). In this case check out the hasSpecificValue function. For the other cases your code (testing for empty string) should work fine, even for attributes that are not of type 'string'/'text'. Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: How to test if some attribute is set of not
llandale - Wed Feb 23 09:32:36 EST 2011

Mathias Mamsch - Wed Feb 23 07:49:51 EST 2011
Sometimes you may want to check if the attribute does not have its "default" value (which could be different from <empty>). In this case check out the hasSpecificValue function. For the other cases your code (testing for empty string) should work fine, even for attributes that are not of type 'string'/'text'. Regards, Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Yes. This should demo it:

string  NameAttr = "MyEnumeratedAttr"
AttrDef ad = find(current Module, NameAttr)
Object  oCurr = current
string  ValuAttr = probeAttr_(oCurr, NameAttr)
 
print identifier(oCurr) "\t" NameAttr "\t"
if    (null ad)         print "No such attribute\n"
elseif(!ad.object)    print "not definded for objects\n"
elseif(null ValueAttr) print "NotDefaultNorInherit\tnull\n"
elseif(!hasSpecificValue(oCurr, ad) 
                      print "YesDefaultOrInherit\t" ValueAttr "\n"
else                   print "Has explicit value\t" ValueAttr "\n"

 

  • Louie

 

Re: How to test if some attribute is set of not
SystemAdmin - Thu Feb 24 03:44:52 EST 2011

Thanks!

Vincent